package com.hk.patterntrains.oberverpattern.typeone;

import java.util.ArrayList;
import java.util.List;

public class WeatherData implements Subject {
    private float temp;
    private float humidity;
    private float pressure;

    private List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObesrver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObesrver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObesrvers() {
        for (Observer observer:observers) {
            observer.update(temp,humidity,pressure);
        }
    }


    public void measurementChanged(){
        notifyObesrvers();
    }

    public void setMeasurements(float temp,float humidity,float pressure){
        this.temp = temp;
        this.humidity = humidity;
        this.pressure = pressure;
    }


}
